{extend name="layout:base" /}

{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="test-table-reload-btn">
                时间
                <div class="layui-input-inline">
                    <input type="text" name="intime" value="{$intime}" class="layui-input" lay-verify="required" id="intime" placeholder="yyyy-MM-dd">
                </div>
                <button class="layui-btn" data-type="reload">搜索</button>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="tbList" class="layui-table" lay-filter="tbList"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    {if condition="$Think.session.admin.levelNum ==50 or  $Think.session.admin.departid==2"}
                    <button class="layui-btn layui-btn-sm" lay-event="back_moneyRepeat">批量返还</button>
                    {/if}
                </div>
            </script>
            <script type="text/html" id="typeid">
                {{#  if(d.typeid ==1){ }}百度{{#  } }}
                {{#  if(d.typeid ==2){ }}360{{#  } }}
                {{#  if(d.typeid ==3){ }}百度移动端{{#  } }}
                {{#  if(d.typeid ==4){ }}sogou{{#  } }}
                {{#  if(d.typeid ==5){ }}神马{{#  } }}
            </script>
        </div>
    </div>
</div>

{/block}

{block name="script"}
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'util', 'form', 'laydate'], function () {
        //表格
        var $ = layui.$, form = layui.form, layer = layui.layer, table = layui.table, laydate = layui.laydate;

        laydate.render({elem: '#intime', max: -1});
        table.render({
            elem: '#tbList',
            url: "{:url('getMoneyRepeat')}",
            toolbar: '#toolbarDemo',
            totalRow: true,
            cellMinWidth: 80,
            cols: [[
                {field: 'keyid', fixed: 'left',width:90, title: 'id'},
                {field: 'url',  title: '网址'},
                {field: 'urlName',title: '公司名称'},
                {field: 'name', title: '关键词'},
                {field: 'typeid',title: '平台',width: 80, templet: '#typeid'},
                {field: 'num',fixed: 'right',width: 80,title: '重复数'},
            ]],
            page: true,
            limit: 15
        });


        table.on('toolbar(tbList)', function(obj){
            switch(obj.event){
                case 'back_moneyRepeat': //批量删除重复
                    var intime = $('#intime').val();
                    layer.open({
                        content: '确认批量返还?'
                        ,btn: ['确定', '取消']
                        ,yes: function(index, layero){
                            $.post("{:url(('/admin/money/back_moneyRepeat'))}",{intime:intime}, function (result) {
                                if (result['code'] == 0) {
                                    layer.msg(result['msg'], {icon: 1, time: 1000}, function () {
                                        //执行重载
                                        table.reload('tbList', {
                                            page: {
                                                curr: 1 //重新从第 1 页开始
                                            }
                                            ,where: {
                                                intime: intime
                                            }
                                        });
                                    });
                                } else {
                                    layer.msg(result['msg'], {icon: 3, time: 3000});
                                }
                            });
                            form.render();
                            layer.close(index);
                        }
                        ,btn2: function(index, layero){
                            layer.close(index);
                        }
                    });
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;
            };
        });


        //操作
        var $ = layui.$, active = {
            add: function (obj) {
                var index = layer.open({
                    type: 2,
                    title: '添加站点',
                    area: ['90%', '90%'],
                    shade: 0,
                    maxmin: true,
                    content: "{:url('add')}?webID=" + wid,
                    zIndex: layer.zIndex
                });
                // layer.full(index);
            },
            reload: function () {
                var t = $('#intime').val();

                //执行重载
                table.reload('tbList', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        intime: t
                    }
                });

            }
        };



        $('.test-table-reload-btn .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>
{/block}